package com.cloudm.technician.ui.modules.personal.change_nick_name

import android.os.Bundle
import android.view.MenuItem
import com.cloudm.technician.R
import com.cloudm.technician.extensions.addFragmentToActivity
import com.cloudm.technician.ui.base.BaseActivity

/**
 * 作者: wesley
 * 时间: 2017/12/26
 * 描述: 修改昵称界面
 */
class ChangeNickNameActivity : BaseActivity() {

    private var fragment: ChangeNickNameFragment? = null
    private var name: String? = null

    override val optionsMenuEnabled: Boolean
        get() = true

    override val menuRes: Int
        get() = R.menu.menu_change_nick_name

    override fun handleBundle(bundle: Bundle) {
        name = bundle.getString("name")
    }

    override fun initVariables() {

    }

    override fun initViews(savedInstanceState: Bundle?) {
        headerTitle = R.string.nick_name
        displayHomeAsUpEnabled = true

        fragment = manager.findFragmentById(
                R.id.common_content) as? ChangeNickNameFragment ?: ChangeNickNameFragment.newInstance(
                name)
        addFragmentToActivity(manager, fragment)
    }

    override fun initListener() {

    }


    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        return when (item?.itemId) {
            R.id.menu_change_nick_name -> {
                fragment?.save()
                true
            }

            else -> false
        }
    }
}